package au.com.carboncycle.gb.engine;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import au.com.carboncycle.core.RingBuffer;
import au.com.carboncycle.gb.engine.Input.Key;

public class Input {
	
	public enum Key {
		UP,
		DOWN,
		LEFT,
		RIGHT,
		JUMP,
		HIGH_PUNCH,
		LOW_PUNCH,
		HIGH_KICK,
		LOW_KICK,
		ESCAPE,
		NO_KEY
	}
	

	//TODO: change this to a priority queue to handle move cancellations
    public List<Key> buttons = Collections.synchronizedList(new LinkedList<Input.Key>());
    public List<Key> oldButtons = new LinkedList<Key>();
    

    public void set(Key button, boolean down) {
        if (button != Key.NO_KEY && down) {
            buttons.add(button);
        }
    }

    public List<Key> tick() {
    	int start, num = 0 ;
		start = oldButtons.size();
		while (!buttons.isEmpty()) {
			oldButtons.add(buttons.remove(0));
			num++;
		}
    	
   
    	return oldButtons.subList(start, start + num);
    }
    
    public void releaseAllKeys() {
        buttons.clear();
    }
}